package com.study.orderserviceprovider.controller;

import com.study.api.Result;
import com.study.orderserviceprovider.dto.OrderDto;
import com.study.orderserviceprovider.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 此类描述的是：
 * @author: 李军容
 * @version: 2020/11/14 20:03
 */

@RestController
public class OrderController {

    @Value("${server.port}")
    private String port;

    @Value("${custom.test.aaa}")
    private String test;


    @GetMapping("/orders")
    public String getAllOrder(){
        System.out.println(port);
        return "Return All ORDERS";
    }

    @GetMapping("/customJson")
    public String customJson(){
        System.out.println(port);
        return test;
    }

    @Autowired
    IOrderService orderService;

    @PostMapping("/order")
    public Result order(@RequestBody @Validated OrderDto orderDto, BindingResult bindingResult){
        orderDto.validData(bindingResult);
        String orderId=orderService.createOrder(orderDto);
        return new Result.Builder<>().data(orderId).ok().bulider();
    }
}
